// 同花顺反爬机制太强了，所以，用JS在控制台手动获取吧，好歹一次20，一个板块能有多少呢？
// 把下面代码复制到控制台，粘贴，就好了

var stockList = []
var getStockList = function () {
  var maincont = document.querySelector('#maincont')
  var tbody = maincont.querySelector('tbody')
  var trs = tbody.querySelectorAll('tr')
  trs.forEach((tr) => {
    var tds = tr.querySelectorAll('td')
    if (tds.length > 2) {
      var code = tds[1].textContent
      var name = tds[2].textContent
      stockList.push(
        {code, name}
      )
    }
  })
  var mPage = document.querySelector('#m-page')
  var aLinks = mPage.querySelectorAll('a')
  var pageInfo = mPage.querySelector('.page_info')
  var maxPage = 0
  if (pageInfo) {
    maxPage = Number(pageInfo.textContent.split('/')[1])
  }
  var nextBtn = Array.prototype.find.call(aLinks, (cell) => {return cell.textContent == '下一页'})
  if (nextBtn && Number(nextBtn.getAttribute('page')) <= maxPage) {
    nextBtn.click()
    setTimeout(() => {
      getStockList()
    }, 2000)
  } else {
    console.log(JSON.stringify(stockList))
    console.log(stockList.length)
  }
}
getStockList()
